<?php
include 'BaseController.php';
class ProjectController extends BaseController
{

    protected $_model = null;

    public function init()
    {
        $this->view->headTitle = "Project";
    }

    public function indexAction()
    {
    }
    public function detailAction()
    {
        $acl = new Middleman_Acl(Zend_auth::getInstance());
        $this->view->headTitle = "Detail a project";
        //get parameter id project in url
        $id = $this->_request->getParam('id');
        if (!((int) $id > 0)) {
            $this->_redirect('/project/list');
        }
        //create project object
        $this->_model = new Application_Model_DbTable_Project();
        //try to get project
        $project = $this->_model->find($id)->current();
        //render project to view
        $this->view->project = $project;
    }

    public function listAction()
    {
        $projectMapper = new Application_Model_ProjectMapper();
        $this->view->projects = $projectMapper->fetchAll();
        $this->view->role = $this->getRole();
    }
    
    public function addAction()
    {
        $this->view->headTitle = "Add";   
               
        $request = $this->getRequest();
        $this->view->values = array();
        if($request->isPost()){
            //set varible values to render view page
            $this->view->values = $request->getParams();
            
            //get data of project from $_Post
            $data = array(
                'name' => $request->getParam('name'),
                'code' => $request->getParam('code'),
                'svn_url' => '',
                'user_id' => '',
                'host_ip' => $request->getParam('host_ip'),
                'host_acc' => $request->getParam('host_acc'),
                'host_pass' => $request->getParam('host_pass'),
                'db_acc' => $request->getParam('db_acc'),
                'db_pass' => $request->getParam('db_pass'),
                'active' => is_null($request->getParam('isActive')) ? 0 : 1,
            );
            
            //create project and store in database
            $this->_model = new Application_Model_DbTable_Project();
            
            //Return project id (id > 0) if insert successfully
            $project = $this->_model->insert($data);
            if($project > 0){
                $this->_redirect('/project/detail/'.$project);
            }
        }
    }

    public function editAction()
    {
        // action body
        $auth = new Zend_Auth_Adapter_DbTable();
    }

    public function deleteAction()
    {
        // action body
    }


}









